package com.hotel.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hotel.daos.GuestMapper;
import com.hotel.entitys.Guest;
import com.hotel.services.GuestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class GuestServiceImpl implements GuestService {
    @Autowired
    private GuestMapper guestMapper;

    @Override

    public PageInfo<Guest> getAllGuest(String keyWord, Integer curentPage, Integer pageSize) { //分页查询
        PageHelper.startPage(curentPage,pageSize);
        List<Guest> l=guestMapper.selectAllGuests(keyWord);
        PageInfo<Guest> pageInfo = new PageInfo(l);
        return pageInfo;
    }

    @Override
    public Guest getUserByNameAndPwd(Integer guest_id) { //查询一条
        return guestMapper.selectUserByPhoneAndPwd(guest_id);
    }

    @Override
    public int addGuest(Guest guest) {  //增加一条
        return guestMapper.saveGuest(guest);
    }

    @Override
    public int deleteAll(Object[] obj) {  //批量删除
        return guestMapper.deleteAll(obj);
    }

    @Override
    public int delete(Integer guest_id) { //删除一行
        System.out.println(guest_id+"sssssssssssssssssssssssssss");
        return guestMapper.deleteGuest(guest_id);
    }

    @Override
    public int update(Guest guest) {  //修改一条
        return guestMapper.updateGuest(guest);
    }

    @Override
    public Guest selGuestByTel(String telephone) {
        return guestMapper.selGuestByTel(telephone);
    }

    @Override
    public int updById(Integer gid) {
        return guestMapper.updById(gid);
    }
}
